package cn.itcast.web.controller.cargo;

import cn.itcast.service.stat.StatService;
import cn.itcast.web.controller.BaseController;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/stat")
public class StatController extends BaseController{

    // 注入dubbo的服务接口的代理对象
    @Reference
    private StatService statService;

    /**
     * 进入统计分页页面
     *http://localhost:8080/stat/toCharts.do?chartsType=factory 生产厂家销售统计
     *http://localhost:8080/stat/toCharts.do?chartsType=sell
     *http://localhost:8080/stat/toCharts.do?chartsType=online
     */
    @RequestMapping("/toCharts")
    public String toCharts(String chartsType){
        return "stat/stat-" + chartsType;
    }

    // 生产厂家销售统计, 返回json格式
    @RequestMapping("/factorySale")
    @ResponseBody
    public List<Map<String, Object>> factorySale(){
        List<Map<String, Object>> list = statService.factorySale();
        return list;
    }

    // 产品销售排行
    @RequestMapping("/productSale")
    @ResponseBody
    public List<Map<String, Object>> productSale(){
        List<Map<String, Object>> list = statService.productSale(5);
        return list;
    }

    // 按小时统计访问人数
    @RequestMapping("/online")
    @ResponseBody
    public List<Map<String, Object>> online(){
        List<Map<String, Object>> list = statService.online();
        return list;
    }

}











